/**
 * 分类路由
 * 定义分类相关的API路由
 */
const express = require('express');
const categoryController = require('../controllers/categoryController');
const authMiddleware = require('../middlewares/auth');

const router = express.Router();

// 所有分类路由都需要认证
router.use(authMiddleware);

/**
 * @swagger
 * /categories: 
 *   get:
 *     summary: 获取分类列表
 *     tags: [分类]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，需要先登录
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 获取分类列表
router.get('/categories', categoryController.getCategories);

/**
 * @swagger
 * /categories: 
 *   post:
 *     summary: 创建分类
 *     tags: [分类]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *                 description: 分类名称，长度为1-20个字符
 *                 minLength: 1
 *                 maxLength: 20
 *                 example: '餐饮'
 *               icon:
 *                 type: string
 *                 description: 分类图标，使用Font Awesome图标类名
 *                 example: 'fa-utensils'
 *               bg_class:
 *                 type: string
 *                 description: 背景颜色类，用于前端展示
 *                 example: 'bg-blue-500'
 *     responses:
 *       200:
 *         description: 创建成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       400:
 *         description: 参数错误，分类名称不能为空或已存在
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，需要先登录
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 创建分类
router.post('/categories', categoryController.createCategory);

/**
 * @swagger
 * /categories/{id}: 
 *   put:
 *     summary: 更新分类
 *     tags: [分类]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 分类ID，必须为正整数
 *         schema:
 *           type: integer
 *           minimum: 1
 *           example: 1
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *                 description: 分类名称，长度为1-20个字符
 *                 minLength: 1
 *                 maxLength: 20
 *                 example: '餐饮'
 *               icon:
 *                 type: string
 *                 description: 分类图标，使用Font Awesome图标类名
 *                 example: 'fa-utensils'
 *               bg_class:
 *                 type: string
 *                 description: 背景颜色类，用于前端展示
 *                 example: 'bg-blue-500'
 *     responses:
 *       200:
 *         description: 更新成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       400:
 *         description: 参数错误
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，需要先登录
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       404:
 *         description: 分类不存在
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 更新分类
router.put('/categories/:id', categoryController.updateCategory);

/**
 * @swagger
 * /categories/{id}: 
 *   delete:
 *     summary: 删除分类
 *     tags: [分类]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 分类ID，必须为正整数
 *         schema:
 *           type: integer
 *           minimum: 1
 *           example: 1
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，需要先登录
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       404:
 *         description: 分类不存在
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       409:
 *         description: 分类已被使用，无法删除
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 删除分类
router.delete('/categories/:id', categoryController.deleteCategory);

module.exports = router;